#import "MainContentView.h"
#import "CameraPreviewView.h"
#import <Masonry/Masonry.h>

@interface MainContentView ()
@property (nonatomic, strong) CameraPreviewView *cameraPreview;
@property (nonatomic, strong) UIButton *lightSettingButton;
@property (nonatomic, strong) UIButton *captureButton;
@end

@implementation MainContentView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        [self cameraPreview];
        [self lightSettingButton];
        [self captureButton];
        [self setupLayout];
    }
    return self;
}

- (CameraPreviewView *)cameraPreview {
    if (!_cameraPreview) {
        _cameraPreview = [[CameraPreviewView alloc] init];
        _cameraPreview.layer.shadowColor = [UIColor darkGrayColor].CGColor;
        _cameraPreview.layer.shadowOpacity = 0.5;
        _cameraPreview.layer.shadowOffset = CGSizeMake(0, 5);
        _cameraPreview.userInteractionEnabled = YES;
        [self addSubview:_cameraPreview];
    }
    return _cameraPreview;
}
- (UIButton *)lightSettingButton {
    if (!_lightSettingButton) {
        _lightSettingButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_lightSettingButton setImage:[UIImage imageNamed:@"arrow_up"] forState:UIControlStateNormal];
        _lightSettingButton.layer.shadowColor = [UIColor darkGrayColor].CGColor;
        _lightSettingButton.layer.shadowOpacity = 0.5;
        _lightSettingButton.layer.shadowOffset = CGSizeMake(0, 5);
        _lightSettingButton.userInteractionEnabled = YES;
        [self addSubview:_lightSettingButton];
    }
    return _lightSettingButton;
}
- (UIButton *)captureButton {
    if (!_captureButton) {
        _captureButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_captureButton setImage:[UIImage imageNamed:@"snapshot"] forState:UIControlStateNormal];
        _captureButton.layer.shadowColor = [UIColor darkGrayColor].CGColor;
        _captureButton.layer.shadowOpacity = 0.5;
        _captureButton.layer.shadowOffset = CGSizeMake(0, 5);
        _captureButton.userInteractionEnabled = YES;
        [self addSubview:_captureButton];
    }
    return _captureButton;
}
- (void)setupLayout {
    [self.cameraPreview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(120);
        make.centerX.equalTo(self);
        make.width.mas_equalTo(260);
        make.height.mas_equalTo(340);
    }];
    [self.captureButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.mas_bottom).offset(-88);
        make.width.height.mas_equalTo(108);
    }];
    [self.lightSettingButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.captureButton.mas_top).offset(-18);
        make.width.height.mas_equalTo(32);
    }];
    
    // 确保按钮在最上层
    [self bringSubviewToFront:self.lightSettingButton];
    [self bringSubviewToFront:self.captureButton];
    

}
@end 
